package com.tjsinfo.tjsoa.addresslist.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjsinfo.tjsoa.addresslist.vo.AddressListGroup;
import com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser;

/**
 * A data access object (DAO) providing persistence and search support for
 * AddressListGroup entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListGroup
 * @author MyEclipse Persistence Tools
 */

public class AddressListSystemUserDAO extends HibernateDaoSupport implements IAddressListSystemUserDAO {
	private static final Log log = LogFactory.getLog(AddressListSystemUserDAO.class);
	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#save(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListGroup)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#save(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void save(AddressListSystemUser transientInstance) {
		log.debug("saving AddressListSystemUser instance");
		try {
			this.getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#update(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void update(AddressListSystemUser transientInstance) {
		log.debug("saving AddressListSystemUser instance");
		try {
			this.getHibernateTemplate().update(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#delete(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListSystemUser)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#delete(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void delete(AddressListSystemUser persistentInstance) {
		log.debug("deleting AddressListSystemUser instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#findById(java.lang.Integer)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#findById(java.lang.String)
	 */
	public AddressListSystemUser findById(java.lang.String id) {
		log.debug("getting AddressListSystemUser instance with id: " + id);
		try {
			AddressListSystemUser instance = (AddressListSystemUser) getHibernateTemplate()
					.get(
							"com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser",
							id);
			return instance;
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#findByExample(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListSystemUser)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#findByExample(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public List findByExample(AddressListSystemUser instance) {
		log.debug("finding AddressListSystemUser instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AddressListSystemUser instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from AddressListSystemUser as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#findAll()
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all AddressListSystemUser instances");
		try {
			String queryString = "from AddressListSystemUser";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#merge(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListSystemUser)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#merge(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public AddressListSystemUser merge(AddressListSystemUser detachedInstance) {
		log.debug("merging AddressListSystemUser instance");
		try {
			AddressListSystemUser result = (AddressListSystemUser) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#attachDirty(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListSystemUser)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#attachDirty(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void attachDirty(AddressListSystemUser instance) {
		log.debug("attaching dirty AddressListSystemUser instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.AddressList_Group.IAddressListGroupDAO#attachClean(com.tjsinfo.tjsoa.addresslist.AddressList_Group.AddressListSystemUser)
	 */
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO#attachClean(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void attachClean(AddressListSystemUser instance) {
		log.debug("attaching clean AddressListSystemUser instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IAddressListGroupDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IAddressListGroupDAO) ctx.getBean("AddressListGroupDAO");
	}
}